package mapper;


import org.apache.ibatis.annotations.*;
import pojo.*;

import java.util.List;

public interface GoodsMapper {


    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from tb_brand ")
    int selectTotalCount();



    /**
     * 分页条件查询
     * @param begin
     * @param size
     * @return
     */

    List<Stock> selectByPageAndCondition(@Param("begin") int begin, @Param("size") int size, @Param("stock") Stock stock);

    List<Invoice> selectByPageAndConditionB(@Param("begin") int begin, @Param("size") int size, @Param("invoice") Invoice invoice);

    /**
     * 根据条件查询总记录数
     * @return
     */

    int selectTotalCountByCondition(Stock stock);
    int selectTotalCountByConditionB(Invoice invoice);

    @Select("select * from inog where gid = #{id}")
    List<InogBean> purchase(int id);

    @Update("UPDATE stock SET number=number + #{num} WHERE id = #{gid};")
    void inGoods(Invoice invoice);

    @Update("UPDATE stock SET number=#{number} WHERE id = #{id};")
    void dos(StockBean stockBean);

    @Update("UPDATE goods SET name=#{name},category=#{category},unit=#{unit} WHERE id = #{id};")
    void alterGoods(Goods goods);

    @Update("UPDATE stock SET number=number - #{num} WHERE id = #{gid};")
    void outGoods(Invoice invoice);

    @Insert("INSERT INTO invoice(flag,gid,createTime,num,tprice,sid) VALUES (#{flag},#{gid},#{createTime},#{num},#{tprice},#{sid})")
    void makeInvoice(Invoice invoice);

    @Insert("INSERT INTO goods(name,category,unit) VALUES (#{name},#{category},#{unit})")
    void addGoods(Goods goods);

    @Delete("delete from goods where id = #{id}")
    void deleteGoods(int id);

    @Insert("INSERT INTO invoice(flag,gid,createTime,num,tprice,sid) VALUES (#{flag},#{gid},#{createTime},#{num},#{tprice},#{sid})")
    void makeOutInvoice(Invoice invoice);

    @Select("select * from user where id = #{id} and passwd = #{passwd}")
    Admin select(@Param("id") String id, @Param("passwd") String passwd);

}
